import React from 'react';
import { Form, Row, DatePicker, Button, Select, Input, Col } from 'antd';
const FormItem = Form.Item;
const { RangePicker } = DatePicker;
const { Option } = Select;

const SearchForm = ({ form: { getFieldDecorator, getFieldsValue }, onSearch, onClick, advanced, searchItem, resetForm, statusList, selectList1, selectList2, selectList3 }) => {
  const onHandleAdvanced = () => {
    if (onClick) {
      onClick();
    }
  };

  const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
      span: 8
    },
    wrapperCol: {
      span: 16
    }
  };
  return (
    <Form className="search-form">
      <Row gutter={24}>
        <Col span={5}>
          <FormItem label="批号"{...formItemLayout}>
            {getFieldDecorator('batchNo', {
              initialValue: searchItem.batchNo || '',
              getValueFromEvent: (event) => {
                return event.target.value.replace(/\s+/g, "")
              },
            })(
              <Input placeholder='请输入批号' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="表单类型"{...formItemLayout}>
            {getFieldDecorator('fromType', {
              initialValue: searchItem.fromType || undefined
            })(
              <Select placeholder='请选择表单类型' allowClear >
                {
                  selectList1.map(item => {
                    return <Option key={item.key}>{item.label}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="状态"{...formItemLayout}>
            {getFieldDecorator('state', {
              initialValue: searchItem.state || undefined
            })(
              <Select placeholder='请选择状态' allowClear >
                {
                  selectList2.map(item => {
                    return <Option key={item.key}>{item.label}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="质检结果"{...formItemLayout}>
            {getFieldDecorator('result', {
              initialValue: searchItem.result || undefined
            })(
              <Select placeholder='请选择质检结果' allowClear >
                {
                  selectList3.map(item => {
                    return <Option key={item.key}>{item.label}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
        </Col>
        <Col span={4} style={{ display: 'flex' }} className="serarch-btns">
          <FormItem>
            <Button icon="search" type="primary" onClick={() => onSearch(getFieldsValue())}>
              {'查询'}
            </Button>
          </FormItem>
          <FormItem>

            <Button type="primary" icon={advanced ? 'up' : 'down'} onClick={() => onHandleAdvanced()}>
              {'展开'}
            </Button>
          </FormItem>
          <FormItem>

            <Button type="default" icon={'redo'} onClick={() => resetForm()}>
              {'重置'}
            </Button>
          </FormItem>
        </Col>
      </Row>
      <Row gutter={24}>

        {
          advanced ?
            <Col span={5}>
              <FormItem label="质检人员"{...formItemLayout}>
                {getFieldDecorator('applyUserName', {
                  initialValue: searchItem.applyUserName || undefined,
                  getValueFromEvent: (event) => {
                    return event.target.value.replace(/\s+/g, "")
                  },
                })(
                  <Input placeholder='请输入质检人员' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
                  // <Select placeholder='请选择质检人员' allowClear >
                  //   {
                  //     statusList.map(item => {
                  //       return <Option key={item.id}>{item.value}</Option>
                  //     })
                  //   }
                  // </Select>
                )}
              </FormItem>
            </Col> : ''
        }
      </Row>

    </Form>
  );
};

export default Form.create()(SearchForm);
